package cn.hy.today;

class Solution_670 {
    public int maximumSwap(int num) {
        char[] arr = String.valueOf(num).toCharArray();
        int n = arr.length;
        int maxNum = num;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                swap(arr, i, j );
                maxNum = Math.max(maxNum, Integer.parseInt(new String(arr)));
                swap(arr, i, j);
            }
        }
        return maxNum;
    }

    private void swap(char[] arr, int i, int j ) {
        char tmp = arr[i];
        arr[i]  = arr[j];
        arr[j] = tmp;
    }
}